package com.lanou3g.dllo.baidumusic.musiclibrary.recommend.allsinger;

import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.base.BaseFragment;
import com.lanou3g.dllo.baidumusic.main.MainActivity;
import com.lanou3g.dllo.baidumusic.tools.MyVolley;
import com.lanou3g.dllo.baidumusic.urlvalues.UrlValues;

/**
 * Created by dllo on 16/6/27.
 */

public class AllSingerFragment extends BaseFragment {

    private AllSingerBean allSingerBean;
    private AllSingerAdapter allSingerAdapter;
    private ImageView allSingerReturnBtn;
    private RelativeLayout huayuLayout;
    private ViewPager allSingerViewPager;

    @Override
    public int setLayout() {
        return R.layout.fragment_allsinger;
    }

    @Override
    public void initView(View view) {
        allSingerViewPager = (ViewPager) view.findViewById(R.id.allsinger_viewpager);
        allSingerAdapter = new AllSingerAdapter(context);
        allSingerBean = new AllSingerBean();
        // 返回上一页
        allSingerReturnBtn = (ImageView) view.findViewById(R.id.allsinger_return_btn);
        allSingerReturnBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getFragmentManager().beginTransaction().remove(getFragmentManager().findFragmentByTag("AllSingerFragment")).commit();
                getFragmentManager().beginTransaction().show(getFragmentManager().findFragmentByTag("MainFragment")).commit();
            }
        });
        // 行布局设置监听,华语男歌手
        huayuLayout = (RelativeLayout) view.findViewById(R.id.huayu_layout);
        huayuLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.HUAYU_MENSINGER, "华语男歌手");
            }
        });
        // 华语女歌手:监听,跳转
        view.findViewById(R.id.huayuwomensinger_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.HUAYU_WOMENSINGER, "华语女歌手");
            }
        });
        // 华语组合:监听,跳转
        view.findViewById(R.id.huayuteam_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.HUAYU_TEAM, "华语组合");
            }
        });
        // 欧美男歌手
        view.findViewById(R.id.oumeimen_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.OUMEI_MENSINGER, "欧美男歌手");
            }
        });
        // 欧美女歌手
        view.findViewById(R.id.oumeiwomen_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.OUMEI_WOMENSINGER, "欧美女歌手");
            }
        });
        // 欧美组合
        view.findViewById(R.id.oumeiteam_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.OUMEI_TEAM, "欧美组合");
            }
        });
        // 韩国男歌手
        view.findViewById(R.id.hanguomen_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.HANGUO_MENSINGER, "韩国男歌手");
            }
        });
        // 韩国女歌手
        view.findViewById(R.id.hanguowomen_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.HANGUO_WOMENSINGER, "韩国女歌手");
            }
        });
        // 韩国组合
        view.findViewById(R.id.hanguoteam_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.HANGUO_TEAM, "韩国组合");
            }
        });
        // 日本男歌手
        view.findViewById(R.id.ribenmen_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.RIBEN_MENSINGER, "日本男歌手");
            }
        });
        // 日本女歌手
        view.findViewById(R.id.ribenwomen_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.RIBEN_WOMENSINGER, "日本女歌手");
            }
        });
        // 日本组合
        view.findViewById(R.id.ribenteam_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.RIBEN_TEAM, "日本组合");
            }
        });
        // 其他歌手
        view.findViewById(R.id.othersinger_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity.toAllSingerDetail(UrlValues.OTHER_SINGER, "其他歌手");
            }
        });

    }

    @Override
    public void initData() {
        MyVolley.getMyVolley().initGson(UrlValues.ALLSINGER_DETAIL, new MyVolley.GetGsonListener<AllSingerBean>() {
            @Override
            public void getGsonListener(AllSingerBean data) {
                allSingerBean = data;
                allSingerAdapter.setAllSingerBean(data);
                allSingerViewPager.setAdapter(allSingerAdapter);
            }
        }, AllSingerBean.class);

        allSingerAdapter.setOnItemClickListener(new AllSingerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int pos) {
                MainActivity mainActivity = (MainActivity) getActivity();
                String tingUid = allSingerBean.getArtist().get(pos).getTing_uid();
                String pictureUrl = allSingerBean.getArtist().get(pos).getAvatar_big();
                mainActivity.toSingerDetail(UrlValues.SINGER_DETAIL_BEFORE + tingUid + UrlValues.SINGER_DETAIL_BEHIDE,tingUid,pictureUrl);
            }
        });

    }
}
